from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

# 实例化驱动
driver = webdriver.Chrome()

# 打开网页
driver.get('https://www.baidu.com/')

# 输入内容
WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((By.ID,'chat-textarea'))).send_keys("刘超班长")

# 点击百度一下
WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((By.ID,'chat-submit-button'))).click()

time.sleep(3)
#Y轴向下500像素
win1 = 'window.scrollBy(0,500)'     # Y轴向下500像素
win2 = 'window.scrollBy(0,-500)'     # Y轴向上500像素
win3 = 'window.scrollBy(500,0)'     # X轴向右500像素
win4 = 'window.scrollBy(-500,0)'     # X轴向左500像素

driver.execute_script(win1)
time.sleep(2)

driver.execute_script(win2)
time.sleep(2)

driver.execute_script(win3)
time.sleep(2)


driver.execute_script(win4)
time.sleep(2)

# 等待
time.sleep(10)
